<?php

class HTML {
	private $attributeId;
	private $attributeClass;
	private $attributeTitle;
	private $childElements;
	private $attributeOnClick;
	private $attributeOnDblClick;
	private $attributeOnFocus;
	private $attributeOnMouseOver;
	private $attributeOnMouseOut;
	
	const ATTRIBUTE_CLASS = 'class';
	const ATTRIBUTE_ID = 'id';
	const ATTRIBUTE_TITLE = 'title';
	const ATTRIBUTE_ONCLICK = 'onclick';
	const ATTRIBUTE_ONDBLCLICK = 'ondblclick';
	const ATTRIBUTE_ONFOCUS = 'onfocus';
	const ATTRIBUTE_ONMOUSEOVER = 'onmouseover';
	const ATTRIBUTE_ONMOUSEOUT = 'onmouseout';
	
	
	public function getHTMLAttributes ()  {
		$output = '';
		if (!empty($this->attributeClass))  {
			$output .= ' '. self::ATTRIBUTE_CLASS. '="'. $this->getAttributeClass(). '"';
		}
		if (!empty($this->attributeId))  {
			$output .= ' '. self::ATTRIBUTE_ID. '="'. $this->getAttributeId(). '"';
		}
		if (!empty($this->attributeTitle))  {
			$output .= ' '. self::ATTRIBUTE_TITLE. '="'. $this->getAttributeTitle(). '"';
		}
		if (!empty($this->attributeOnClick))  {
			$output .= ' '. self::ATTRIBUTE_ONCLICK. '="'. $this->getAttributeOnClick(). '"';
		}
		if (!empty($this->attributeOnDblClick))  {
			$output .= ' '. self::ATTRIBUTE_ONDBLCLICK. '="'. $this->getAttributeOnDblClick(). '"';
		}
		if (!empty($this->attributeOnFocus))  {
			$output .= ' '. self::ATTRIBUTE_ONFOCUS. '="'. $this->getAttributeOnFocus(). '"';
		}
		if (!empty($this->attributeOnMouseOver))  {
			$output .= ' '. self::ATTRIBUTE_ONMOUSEOVER. '="'. $this->getAttributeOnMouseOver(). '"';
		}
		if (!empty($this->attributeOnMouseOut))  {
			$output .= ' '. self::ATTRIBUTE_ONMOUSEOUT. '="'. $this->getAttributeOnMouseOut(). '"';
		}
		if ($output == '')  {
			$output = ' ';
		}
		
		return $output;
	}
	
	public function setAttributeId ($id)  {
		$this->attributeId = $id;
	}
	
	public function setAttributeClass ($class)  {
		$this->attributeClass = $class;
	}
	
	public function setAttributeTitle ($title)  {
		$this->attributeTitle = $title;
	}
	
	public function setAttributeOnClick ($onClick)  {
		$this->attributeOnClick = $onClick;
	}
	
	public function setAttributeOnDblClick ($onDblClick)  {
		$this->attributeOnDblClick = $onDblClick;
	}
	
	public function setAttributeOnFocus ($onFocus)  {
		$this->attributeOnFocus = $onFocus;
	}
	
	public function setAttributeOnMouseOver ($onMouseOver)  {
		$this->attributeOnMouseOver = $onMouseOver;
	}
	
	public function setAttributeOnMouseOut ($onMouseOut)  {
		$this->attributeOnMouseOut = $onMouseOut;
	}
	
	public function getAttributeId ()  {
		return $this->attributeId;
	}
	
	public function getAttributeClass ()  {
		return $this->attributeClass;
	}
	
	public function getAttributeTitle ()  {
		return $this->attributeTitle;
	}
	
	public function getAttributeOnClick ()  {
		return $this->attributeOnClick;
	}
	
	public function getAttributeOnDblClick ()  {
		return $this->attributeOnDblClick;
	}
	
	public function getAttributeOnFocus ()  {
		return $this->attributeOnFocus;
	}
	
	public function getAttributeOnMouseOver ()  {
		return $this->attributeOnMouseOver;
	}
	
	public function getAttributeOnMouseOut ()  {
		return $this->attributeOnMouseOut;
	}
	
	public function addChildElement ($element)  {
		$this->childElements[] = $element;
	}
	
	public function getChildElements ()  {
		if (empty($this->childElements))  {
			return false;
		}
		return $this->childElements;
	}
	
	public static function getAttributes ()  {
		$attributes = array();
		$attributes[] = self::ATTRIBUTE_CLASS;
		$attributes[] = self::ATTRIBUTE_ID;
		$attributes[] = self::ATTRIBUTE_TITLE;
		$attributes[] = self::ATTRIBUTE_ONCLICK;
		$attributes[] = self::ATTRIBUTE_ONDBLCLICK;
		$attributes[] = self::ATTRIBUTE_ONFOCUS;
		$attributes[] = self::ATTRIBUTE_ONMOUSEOVER;
		$attributes[] = self::ATTRIBUTE_ONMOUSEOUT;
		
		return $attributes;
	}
	
	public function toString ()  {
		
		$output = '';
		if ($this->getChildElements())  {
			foreach ($this->getChildElements() as $element)  {
				$output .= $element->toString();
			}
		}
		
		
//
//		Activate on server to get a nice HTML - Source
//		
		//$tidy = tidy_parse_string($output);
		//$output = $tidy->html();
		
// unset all variables in order to destroy the output
		unset($this->childElements);
		unset($this->attributeId);
		unset($this->attributeClass);
		unset($this->attributeTitle);
		
		return $output;
	}
}

?>